package com.zhj.leetcode;

import java.util.HashSet;

/**
 * 力扣1456 定长(k)子串中可能包含的最大元婴音字母
 * 元音字母为（a,e,i,o,u）
 * @author zhj
 */
public class Test1456 {
    public static void main(String[] args) {
        String s = "abciiidef";
        int k = 3;
        System.out.println(YY(s,4));
    }
    private static int YY(String s, int k){
        if ("".equals(s) || k > s.length()) {
            return 0;
        }
        HashSet set = new HashSet();
        set.add('a');
        set.add('e');
        set.add('i');
        set.add('o');
        set.add('u');
        int res = 0;
        int count = 0;
        char[] chars = s.toCharArray();
        for (int i = 0; i < k; i++) {
            if (set.contains(chars[i])){
                count++;
            }
        }
        res = res > count ? res : count;
        for (int i = k; i < chars.length; i++) {
            if (set.contains(chars[i-k])) {
                count--;
            }
            if (set.contains(chars[i])) {
                count++;
            }
            res = res > count ? res : count;
        }
        return res;
    }
}
